package com.example.forum2.controller;

import com.example.forum2.common.AppResult;
import com.example.forum2.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

@Api(tags = "测试类的相关接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1,显式打印")
    @GetMapping("/t1")
    public String t1(){
        return  "dasdfas   ";
    }
    @GetMapping("/t2")
    public String t2(){
        return  "dasdfas   ";
    }
    @ApiOperation("测试接口4,显式打印传递的字符串")
    @PostMapping("/t3")
    public String hello(@ApiParam("需要传入的姓名") @RequestParam("t") String t){
        return t;
    }



    @ApiOperation("测试接口2,显式异常信息")

    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw  new Exception("这是一个Exception...");
    }
    @ApiOperation("测试接口3,显式自定义异常信息")

    @GetMapping("/appException")
    public AppResult testAppkicationException(){
        throw new ApplicationException("sdfs");
    }

}

//@Api注解作用在Controller上,是对控制器的说明